/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketmaster.businesslogic;

import javax.security.cert.CertificateException;
//import ticketmaster.businessobject.Administrator;
//import ticketmaster.businessobject.Clerk;
import ticketmaster.dataobject.Customer;
//import ticketmaster.businessobject.Customer;
import ticketmaster.common.UserRoles;
import ticketmaster.dao.DAOFactory;
import ticketmaster.dao.UserDAO;
import ticketmaster.dao.CustomerDAO;
import ticketmaster.dao.PremiumCustomerDAO;
import ticketmaster.dataobject.PremiumCustomer;
import ticketmaster.dataobject.User;
import ticketmaster.security.Encryption;

/**
 *
 * @author Tingting
 */
public class RegisterController {

    public RegisterController()
    {

    }
    public boolean updateRegUser(User user){
        UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
        return userDAO.updateUser(user);
    }

    public boolean updateRegCustomer(Customer customer){
        CustomerDAO customerDAO = DAOFactory.getInstance().getCustomerDAO();
        return customerDAO.updateCustomer(customer);
    }

    public User findRegUser(User user){
        UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
        return userDAO.findUser(user);
    }

    public Customer fingRegCustomer(Customer customer){
        CustomerDAO customerDAO = DAOFactory.getInstance().getCustomerDAO();
        return customerDAO.findCustomer(customer);
    }

    public int RegisterUser(User user)
    {
        UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
        return userDAO.insertUser(user);
    }
    public int RegisterPremiumCustomer(PremiumCustomer premiumcustomer){
        PremiumCustomerDAO premiumcustomerDAO = DAOFactory.getInstance().getPremiumCustomerDAO();
        return premiumcustomerDAO.insertPremiumCustomer(premiumcustomer);
    }

    public Customer registerCustomer(Customer customer) throws CertificateException
    {   
        CustomerDAO customerDAO = DAOFactory.getInstance().getCustomerDAO();
        customerDAO.insertCustomer(customer);
       // ticketmaster.businessobject.Customer RegisterCustomer = null;
      /* Customer customer = new Customer();

        //UserDAO userDAO = DAOFactory.getInstance().getUserDAO();

        CustomerDAO customerDAO = DAOFactory.getInstance().getCustomerDAO();
        customerDAO.insertCustomer(customer);

        User user = new User();
        user.setUserRoleID(UserRoles.Customer.ordinal());
        user.setUsername(username);
        user.setPassword(Encryption.md5(password));
        int i = customerDAO.insertCustomer(customer);

        Customer validatedCustomer = this.getCustomerDAO().findCustomer(customer);

        ticketmaster.businessobject.Customer RegisterCustomer = null;

        if(validatedCustomer == null)
        {
            if ((!(email.equals("")))  && (email.equals(email2))){
                customer.setEmailAddress(email);
            }
            else if (!(password.equals("")) && (password.equals(password2))){
                RegisterCustomer.setPassword(password);
            }
            else if (!(address1.equals(""))){
                customer.setAddressLine1(address1);
            }
            else if (!(city.equals(""))){
                customer.setCity(city);
            }
            
                        
            customer.setFirstName(firstname);
            customer.setLastName(lastname);
            customer.setPostcode(postcode);
            customer.setPhoneNo(phone);
            customer.setProvince(province);
            RegisterCustomer.setUserID(validatedCustomer.getCustomerID());
            RegisterCustomer.setUsername(username);
            RegisterCustomer.setPassword(password);
            customer.setCustomerID(i);
        }
        else
        {
            throw new CertificateException("There was a problem with your submission!");
        }*/

        //return RegisterCustomer;
         return null;
    }

     
}
